﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Base<T> : IBase<T> where T : class
    {
        public Base(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }

        public async Task<int> AddAsync(T t)
        {
           Context.Set<T>().Add(t);
            return await Context.SaveChangesAsync();

        }

        public async Task<int> DeleteAsync(int id)
        {
            var obj = await Context.Set<T>().FindAsync(id);
            Context.Set<T>().Remove(obj);
            return await Context.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return Context.Set<T>();
        }

       
    }
}
